package com.situ.mall.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.situ.mall.admin.entity.User;
import com.situ.mall.admin.mapper.UserMapper;
import com.situ.mall.admin.service.IUserService;
import com.situ.mall.common.util.RequestUtil;
import com.situ.mall.common.util.StringUtil;
import com.situ.mall.common.vo.TableVO;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author kkkkkk
 * @since 2023-09-11
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public TableVO selectList(Integer page, Integer limit, String username, String name, String status) {
        PageHelper.startPage(page, limit);
        return TableVO.data(baseMapper.list(username, name, status));
    }

    @Override
    public boolean check(String username, String password) {
        User u = baseMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getUsername, username));
        boolean b = u != null && u.getPassword().equals(StringUtil.md5(password));
        if (b) {
            //把当前用户保存进session
            RequestUtil.setCurrent(u);
        }
        return b;
    }
}
